Repository navigation
Fix: roll back meta document and storage instance when createRxCollection() fails in addCollections() - #9595
Conversation
✅ Verify Test Reproduction: Tests FAILED without the fix (expected)This confirms the changed tests correctly reproduce the bug that the source changes fix. This workflow runs the changed tests without the source fix to verify they reproduce the bug. Show output |
5dbb5fb to
01ff046
Compare
|
Pushed 8169fb9. It removes the migration test that built its own Dexie.js storage. I first moved it to A separate finding from that attempt, not changed here: on the memory storage Generated by Claude Code |
8169fb9 to
25821fd
Compare
…tion() fails in addCollections() Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6hnnyVPXwotts6YQ2F
… closed before the rollback The rollback of a failed collection creation is skipped when the database is closing or closed, and an error inside the rollback no longer replaces the creation error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6hnnyVPXwotts6YQ2F
The test built its own dexie storage on fake-indexeddb. With the storage of the test config it never settles on the memory storage, with and without the fix, because addCollections() does not settle when the database is closed during a migration there. On dexie, localstorage and remote it passes also without the fix, so it does not show the bug on any storage. The fix stays covered by the test in rx-database.test.ts, which uses the storage of the test config and fails without the fix on each storage. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6hnnyVPXwotts6YQ2F
25821fd to
58bcb66
Compare
createRxCollection() closed the storage instance of a failed collection but left the collection itself open. With the rollback of addCollections() this caused two failures: - The failed collection still listened to the internal store. When the rollback deleted the meta document, the failed collection called close() and removed the later collection with the same name from database.collections, so database.close() no longer closed it (last.test.ts "ensure all collections are closed"). - The cleanup plugin kept running on the failed collection and called cleanup() on the removed storage (sqlite: "no such table: items-0"). The rollback code is also written shorter so that the memory-minimal bundle stays inside its size limit (146873 bytes, limit 146885). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6hnnyVPXwotts6YQ2F
This PR contains:
Describe the problem you have without this PR
addCollections()left the collection meta document and the storage instance behind when the creation of the collection failed after the storage instance was created (for example withCOL17), so that adding the collection again with an adjusted schema threwDB6Covers a failure inside
createRxCollection()after the storage instance exists, for exampleCOL17. pubkey/rxdb#9577 covers the case where the storage rejects the creation of the storage instance and changes the same block.multiInstance: when another tab adds the same collection at the same moment and succeeds while the creation in this tab fails, the rollback removes the storage instance and meta document that the other tab uses.COL17.Changed files:
orga/changelog/fix-failed-collection-creation-leaves-meta-document.jsonsrc/rx-database.tstest/unit/rx-database.test.tsTest output without the fix
The changed test file run on the memory storage with
src/frommaster:Test output with the fix
Todos
Assisted by
YES, CLAUDE CODE
Generated by Claude Code